﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Cloud.Model;
using Cloud.BLL;
using System.Configuration;

public partial class Three_Managerment_Problem_PY_List_dpy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["users"] == null)
        {
            Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
        }
        if (!IsPostBack)
        {
            #region 下拉数据绑定
            this.gs_drop.DataSource = AscriptionManager.FindAll();
            this.gs_drop.DataTextField = "name";
            this.gs_drop.DataValueField = "id";
            this.gs_drop.DataBind();
            this.gs_drop.Items.Insert(0, new ListItem("全部", "0"));

            this.sqly_drop.DataSource = SourcesManager.FindAll();
            this.sqly_drop.DataTextField = "name";
            this.sqly_drop.DataValueField = "id";
            this.sqly_drop.DataBind();
            this.sqly_drop.Items.Insert(0, new ListItem("全部", "0"));
            #endregion

            bind();

        }
    }
    protected void AspNetPager_PageChanged(object sender, EventArgs e)
    {
        if (Session["users"] == null)
        {
            Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
        }
        bind();
    }

    public void bind()
    {
        string strbid = "select * from problem where 1=1 ";
        string strsjzt = " and handle_type = 3 ";
        string strsjid = "";
        string strgs = "";
        string strsqly = "";
        string strsly = "";
        string strbegtime = "";
        string strtimeend = "";
        string strend = "  order by id desc ";
        #region 受理员 1
        if (sly_input.Value.Equals(""))
        {

        }
        else
        {
            strsly = " and jobnum =" + sly_input.Value + " ";
        }
        #endregion
        #region 诉求来源 1
        if (sqly_drop.SelectedItem.Value.Equals("0"))
        {

        }
        else
        {
            strsqly = " and source_id =" + sqly_drop.SelectedItem.Value + " ";
        }
        #endregion
        #region 归属 1
        if (gs_drop.SelectedItem.Value.Equals("0"))
        {

        }
        else
        {

            strgs = " and ascription_id =" + gs_drop.SelectedItem.Value + " ";
        }
        #endregion
        #region 事件id  1


        if (sjid_input.Value.Equals(""))
        {

        }
        else
        {
            strsjid = " and appealid  = '" + sjid_input.Value + "' ";
        }
        #endregion
        
        #region 时间
        if (!this.timebeg.Value.Equals("") && !this.timeend.Value.Equals(""))
        {
            if (Convert.ToDateTime(this.timeend.Value) < Convert.ToDateTime(this.timebeg.Value))
            {
                Response.Write("<script>alert('时间选择错误')</script>");
            }
        }
        if (!this.timebeg.Value.Equals(""))
        {
            strbegtime = " and regtime > '" + this.timebeg.Value + "' ";
        }

        if (!this.timeend.Value.Equals(""))
        {
            strtimeend = " and regtime < '" + this.timeend.Value + "' ";
        }
        #endregion


        String sqls = strbid + strsjid + strsjzt + strgs + strsly + strsqly + strbegtime + strtimeend + strend;
        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
        SqlCommand cmd = new SqlCommand(sqls, connection);
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        AspNetPager1.PageSize = 10;//设置分页大小 
        AspNetPager1.RecordCount = ProblemManager.FindAll().Count;//设置总数据条数 
        sda.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "problem");//固定不变的 
        repeater.DataSource = ds.Tables["problem"];
        repeater.DataBind();
    }
    protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater rep = e.Item.FindControl("rep1") as Repeater;//找到里层的repeater对象
            DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
            int typeid = Convert.ToInt32(rowv["id"]); //获取填充子类的id 
            IList<Sources> sou = new List<Sources>();
            sou.Add(SourcesManager.FindById(typeid));
            rep.DataSource = sou;
            rep.DataBind();
        }
    }

    //事件状态
    public string sjzt(int i)
    {
        String zts = "";
        if (i == 0)
        {
            zts = "满意";
        }
        else if (i == 1)
        {
            zts = "一般";
        }
        else if (i == 2)
        {
            zts = "已办理";
        }
        else if (i == 3)
        {
            zts = "已办结";
        }
        else if (i == 9)
        {
            zts = "未评议";
        }
        return zts;

    }
    protected void Unnamed_Click(object sender, EventArgs e)
    {
        this.bind();
    }
}